require("../util.js");
require("../component/components.js");
require("../component/purchaseHeader.js");
require("../component/basicSlide.js");
require("../component/footer.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#purchaseIndex",
    data:{
        mainList:{},//主页接口
        seckillsList:[],//秒杀
        hours:"",//时
        minutes:"",//分
        seconds:"",//秒
        endDate:"",
        endSecond:"",
        startsecond:""
    },
    mounted:function(){
        this.getMainList();
        // this.compareDate()
    },
    methods:{
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        //乐购主页接口
        getMainList:function(){
            var that=this;
            this.ajax({url:"/purchase/getMainList",dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.mainList=b.json.data;
                    that.seckillsList=that.mainList.seckills[0];
                    that.endDate=that.seckillsList.endDate;
                    that.endSecond=parseInt(that.endDate)*60*60;
                    that.compareDate();
                    // console.log(that.endDate)
                    // console.log(that.endSecond)
                }else{
                    vm.$refs.prompt.toast("乐购主页接口！")
                }
            });
        },
        compareDate:function(){
            a=setInterval(this.leftTimer,1000);
            //this.leftTimer();
        },
        //时分秒倒计时
        leftTimer:function(){
            var that=this;
            var date = new Date();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            this.startsecond=(hour*60+minute)*60+second;
            if(that.endSecond>that.startsecond){
                that.hours=Math.floor((that.endSecond-that.startsecond)/60/60);
                that.minutes=Math.floor((that.endSecond-that.startsecond)/60%60);
                that.seconds=Math.floor((that.endSecond-that.startsecond)%60);
                that.hours=checkTime(that.hours);
                that.minutes=checkTime(that.minutes);
                that.seconds=checkTime(that.seconds);
            }else{
                clearInterval(a);
            }
        },
        //跳转页面
        getNext:function(type,id){
            console.log(id)
            location.href="/purchase/goodsDetails?productId="+id+"&type="+type
        }
    }
});
var a;
function checkTime(i){ //将0-9的数字前面加上0，例1变为01
    if(i<10){
        i = "0" + i;
    }
    return i;
}